<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('流程模型列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <p>名称：</p>
                                <input type="text" name="name"/>
                            </li>
                            <li>
                                <p>部署ID：</p>
                                <input type="text" name="deploymentId"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="activiti:model:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table" data-mobile-responsive="true"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('activiti:model:edit')}]];
        var removeFlag = [[${@permission.hasPermi('activiti:model:remove')}]];
        var designFlag = [[${@permission.hasPermi('activiti:model:design')}]];
        var deployFlag = [[${@permission.hasPermi('activiti:model:deploy')}]];

        var prefix = ctx + "activiti/model";

        /**
         * 设计模型
         * @param id
         */
        function design(id) {
            var url = prefix + "/design/" + id;
            layer.open({
                type: 2,
                title: "设计模型",
                content: url,
                area: ['100%', '100%'],
                maxmin: true,
                success: function(layero,index){
                    layer.full(index);
                }
            });
        }

        /**
         * 部署模型
         * @param id
         */
        function deploy(id) {
            var url = prefix + "/deploy/" + id;
            $.ajax({
                type: "get",
                url: url,
                data: {

                },
                async:true,
                dataType: "json",
                success:function (obj) {
                    if (obj) {
                        layer.msg("部署成功：" + obj.msg);
                    }
                },
                error:function (err) {
                    console.log(err);
                }
            });
        }
        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove/{id}",
                exportUrl: prefix + "/export",
                modalName: "流程模型",
                columns: [{
                    checkbox: true
                },
                {
                    field : 'id', 
                    title : 'id',
                    visible: false
                },
                {
                    field : 'rev', 
                    title : '乐观锁'
                },
                {
                    field : 'name', 
                    title : '名称'
                },
                {
                    field : 'key', 
                    title : 'KEY_'
                },
                {
                    field : 'category', 
                    title : '分类'
                },
                {
                    field : 'createTime', 
                    title : '创建时间'
                },
                {
                    field : 'lastUpdateTime', 
                    title : '最新修改时间'
                },
                {
                    field : 'version', 
                    title : '版本'
                },
                {
                    field : 'metaInfo', 
                    title : 'META_INFO_'
                },
                {
                    field : 'deploymentId', 
                    title : '部署ID'
                },
                {
                    title: '操作',
                    align: 'center',
                    width:  "300px",
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + designFlag + '" href="javascript:void(0)" onclick="design(\'' + row.id + '\')"><i class="fa fa-wrench"></i>设计</a> ');
                        actions.push('<a class="btn btn-success btn-xs ' + deployFlag + '" href="javascript:void(0)" onclick="deploy(\'' + row.id + '\')"><i class="fa fa-location-arrow"></i>部署</a> ');
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a>');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
    </script>
</body>
</html>